﻿using System;
using System.Collections.Generic;
using Android.Graphics;
using Android.Runtime;
using Android.Support.V7.Widget;
using Android.Views;
using static Android.Support.V7.Widget.GridLayoutManager;
using static Android.Support.V7.Widget.RecyclerView;

namespace mb.Droid
{
    public class MySpanSizeLookup : SpanSizeLookup
    {
        public Func<int, int> MyGetSpanSize;
        public override int GetSpanSize(int position)
        {
            return MyGetSpanSize(position);
        }
    }

    public class MyRecyclerViewHolder : RecyclerView.ViewHolder
    {
        public Dictionary<string, object> data;
        public Action<int> MyUpdate;
        public MyRecyclerViewHolder(View itemView) : base(itemView)
        {

        }
    }
    public class MyItemDecoration : RecyclerView.ItemDecoration
    {
        public override void GetItemOffsets(Rect outRect, Android.Views.View view, RecyclerView parent, State state)
        {
            (parent.GetAdapter() as MyRecyclerAdapter).MyGetItemOffset?.Invoke(outRect, view, state);
        }
    }

    public class MyRecyclerAdapter : RecyclerView.Adapter
    {
        public Func<ViewGroup, int, RecyclerView.ViewHolder> MyOnCreateViewHolder;
        public Func<int> MyItemCount;
        public Func<int, int> MyGetItemViewType;
        public Func<int, int> MyGetItemId;
        public Action<RecyclerView.ViewHolder, int> MyOnBindViewHolder;
        public Action<Rect, View, State> MyGetItemOffset;

        public override long GetItemId(int position)
        {
            return MyGetItemId?.Invoke(position) ?? base.GetItemId(position);
        }
        public override RecyclerView.ViewHolder OnCreateViewHolder(ViewGroup parent, int viewType)
        {
            return MyOnCreateViewHolder(parent, viewType);
        }

        public override void OnBindViewHolder(RecyclerView.ViewHolder holder, int position)
        {
            MyOnBindViewHolder(holder, position);
        }

        public override int ItemCount => MyItemCount();

        public override int GetItemViewType(int position)
        {
            return MyGetItemViewType?.Invoke(position) ?? 0;
        }
    }
}